package com.op.converter;

import com.op.constants.DifficultyConstant;
import com.op.constants.StatusConstant;

/**
 * ClassName： QuestionConverter
 * Date： 2021/10/24 13:30
 *
 * @author 孤焰
 * @version 1.0
 **/

public class QuestionConverter {
    /**
     * 将题目难度从int类型向String类型转换
     * @param difficulty 题目难度
     * @return 字符串类型的题目难度
     */
    public static String convertDiffIntToString(Integer difficulty) {
        switch (difficulty) {
            case 0:
                return DifficultyConstant.UN_KNOWN;
            case 1:
                return DifficultyConstant.SIMPLE;
            case 2:
                return DifficultyConstant.MEDIUM;
            case 3:
                return DifficultyConstant.DIFFICULT;
            default:
                return DifficultyConstant.ERROR;
        }
    }

    /**
     * 将题目难度从String类型向int类型转换
     * @param difficulty 题目难度
     * @return int类型的题目难度
     * @throws Exception
     */
    public static Integer convertDiffStringToInt(String difficulty) throws Exception {
        switch (difficulty) {
            case DifficultyConstant.UN_KNOWN:
                return 0;
            case DifficultyConstant.SIMPLE:
                return 1;
            case DifficultyConstant.MEDIUM:
                return 2;
            case DifficultyConstant.DIFFICULT:
                return 3;
            default:
                throw new Exception("题目难度转换异常, difficulty:" + difficulty);
        }
    }

    /**
     * 将题目状态从int类型向String类型转换
     * @param status 题目状态
     * @return 字符串类型的题目状态
     */
    public static String convertStatusIntToString(Integer status) {
        switch (status) {
            case 0:
                return StatusConstant.UNABLE;
            case 1:
                return StatusConstant.ENABLE;
            default:
                return StatusConstant.ERROR;
        }
    }

    /**
     * 将题目状态从String类型向int类型转换
     * @param status 题目状态
     * @return int类型的题目状态
     * @throws Exception
     */
    public static Integer convertStatusStringToInt(String status) throws Exception {
        switch (status) {
            case StatusConstant.ENABLE:
                return 0;
            case StatusConstant.UNABLE:
                return 1;
            default:
                throw new Exception("题目状态转换异常, status:" + status);
        }
    }
}
